@extends('public.dashboard_base')
@section('title', '申请提现')

@section('content')
    <div class="control_panel_content">
        <div class="navBreadcrumb">
            <ul>
                <li>资金管理</li>
                <li><a href="/funds/withdrawal">申请提现</a></li>
            </ul>
        </div>
        <div class="panel">
            <div class="sub_nav_container">
                <ul class="clearfix">
                    <li><a href="/funds/withdrawal/setting">设置提现账户</a></li>
                    <li class="active"><a href="/funds/withdrawal">申请提现</a></li>
                    <li><a href="/funds/withdrawal/list">提现列表</a></li>
                </ul>
            </div>
            <div class="panel_body">
                {{--                <dl class="remind_box">--}}
                {{--                    <dt>--}}
                {{--                        <i class="iconfont iconremind"></i>--}}
                {{--                        提示：您还未设置有效的提现账户信息，无法申请提现    <a href="/funds/withdrawal/setting"> 提现设置 </a>--}}
                {{--                    </dt>--}}
                {{--                </dl>--}}
                <form class="layui-form">
                    {{csrf_field()}}
                    <ul class="form_group">
                        <li>
                            <span class="form_label">可提现金额</span>
                            <span class="f16">{{$user->cash}}</span>
                        </li>
                        <li>
                            <span class="form_label">提现账户</span>
                            <dl class="withdraw_account_type clearfix">
                                @forelse ($withdrawal_access as $item)
                                    {{--                                    <dd class="disabled">--}}
                                    {{--                                        <div class="icon"><i class="iconfont iconbank"></i></div>--}}
                                    {{--                                        <p>暂未设置</p>--}}
                                    {{--                                        <span class="selected"><i class="iconfont iconcheck text_orange"></i></span>--}}
                                    {{--                                    </dd>--}}
                                    {{--                                    <dd class="WEIXIN">--}}
                                    {{--                                        <div class="icon"><i class="iconfont iconweixin  text_green"></i></div>--}}
                                    {{--                                        <p>暂未设置</p>--}}
                                    {{--                                        <span class="selected"><i class="iconfont iconcheck text_orange"></i></span>--}}
                                    {{--                                    </dd>--}}
                                    <dd data-type="ALIPAY" class="active">
                                        <div class="icon"><i class="iconfont iconalipay text_blue"></i></div>
                                        <p>{{ $item->name }}</p>
                                        <p>{{ $item->access }}</p>
                                        <input type="hidden" name="type" value="{{ $item->type }}">
                                        <span class="selected"><i class="iconfont iconcheck text_orange"></i></span>
                                    </dd>

                                @empty
                                    <span class="text_red">未设置提现账户</span>
                                    <a href="/funds/withdrawal/setting">前往设置</a>
                                @endforelse
                            </dl>
                        </li>
                        <li>
                            <span class="form_label">提现金额</span>
                            <input type="text" name="amount" onkeyup="validateAmount(this)">
                            手续费：<span class="text_orange" id="service_charge">0.00</span>元，
                            实际到账：<span class="text_orange" id="arrival_amount">0.00</span>元
                        </li>
                        {{--                        <li>--}}
                        {{--                            <span class="form_label"><span class="tips_box"><i--}}
                        {{--                                            class="iconfont iconwenhao text_light_gray"--}}
                        {{--                                            style="font-size: 14px;font-weight: 400"></i><span class="text"--}}
                        {{--                                                                                               style="width:210px;white-space:normal">操作验证保障您的账户安全，可以在安全中心-&gt;<a--}}
                        {{--                                                href="/user/editsj"--}}
                        {{--                                                style="color: #2196F3">修改手机</a>中进行个性化设置。</span></span>&nbsp;手机号码</span>--}}
                        {{--                            <div style="width: 280px;display: inline-block;vertical-align: middle;height: 32px;line-height: 26px;">--}}
                        {{--                                <span style="vertical-align: middle">15166664603</span>--}}
                        {{--                                <input type="button" id="sms_send" class="btn btn_default fr" value="获取验证码">--}}
                        {{--                            </div>--}}
                        {{--                        </li>--}}
                        {{--                        <li>--}}
                        {{--                            <span class="form_label">验证码</span>--}}
                        {{--                            <input type="text" name="authCode" id="authCode">--}}
                        {{--                        </li>--}}
                        <li>
                            <span class="form_label">&nbsp;</span>
                            <button class="btn btn_primary" lay-submit lay-filter="submit">确认提现</button>
                        </li>
                    </ul>
                </form>
            </div>
        </div>
        <div class="warm_prompt">
            <div class="title">温馨提示</div>
            <ul>
                <li>1、申请提现后您的款项将在3-5个工作日内转账到您的提现账户。</li>
                <li>2、可提现金额为账户可用金额，不包含冻结金额。提现手续费{{config('withdrawal.service_charge')}}%。</li>
            </ul>
        </div>
    </div>
@endsection
@section('script')
    <script>
        $(function () {
            var link = $("#funds-withdrawal");
            link.parent().parent().parent().addClass("active");
            link.parent().addClass("active");
        });

        function validateAmount(that) {
            var val = $(that).val();
            val = val.replace(/[^\d.]/g, "").replace(/^\./g, "").replace(/\.{2,}/g, ".").replace(".", "$#$").replace(/\./g,
                "").replace("$#$", ".").replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
            $(that).val(val);
            var serviceCharge = (val * "{{config('withdrawal.service_charge')}}" / 100).toFixed(2);
            clearTimeout(this.timer);
            this.timer = setTimeout(function () {
                $('#service_charge').html(serviceCharge);
                $('#arrival_amount').html((val - serviceCharge).toFixed(2));
            }, 500);
        }

        //监听提交
        layui.form.on('submit(submit)', function (data) {
            var submit = $(this);
            submit.attr('disabled', 'disabled');
            submit.addClass('layui-btn-disabled');
            $.ajax({
                url: "",
                type: "post",
                //dataType:"text",
                data: data.field,
                success: function (data) {
                    if (data.msg === 'success') {
                        layer.msg('成功', {icon: 1, time: 500}, function () {
                            //   window.location.reload(); //刷新页面
                            window.location.href = "/funds/withdrawal/list" //指定路径
                            //  history.go(-1) //后退

                        })
                    } else {
                        layer.msg(data.msg, {icon: 2});
                        submit.removeAttr('disabled');
                        submit.removeClass('layui-btn-disabled');
                    }
                },
                error: function (xhr, Status, error) {
                    layer.msg(Status + ':' + xhr.responseJSON.data, {icon: 2});
                    submit.removeAttr('disabled');
                    submit.removeClass('layui-btn-disabled');
                }
            });
            return false;
        });
    </script>
@endsection
